home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / lib / getconfig.c < prev    next >
C/C++ Source or Header  |  1993-01-29  |  2KB  |  82 lines

  1. /*  $Revision: 1.10 $
  2. **
  3. */
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include "configdata.h"
  7. #include "paths.h"
  8. #include "clibrary.h"
  9. #include "libinn.h"
  10. #include "macros.h"
  11.  
  12.  
  13. /* Global and initialized; to work around SunOS -Bstatic bug, sigh. */
  14. STATIC char        ConfigBuff[SMBUF] = "";
  15.  
  16.  
  17. char *
  18. GetFileConfigValue(value)
  19.     register char    *value;
  20. {
  21.     register FILE    *F;
  22.     register int    i;
  23.     register char    *p;
  24.     register char    c;
  25.  
  26.     /* Read the config file. */
  27.     if ((F = fopen(_PATH_CONFIG, "r")) != NULL) {
  28.     c = *value;
  29.     i = strlen(value);
  30.     while (fgets(ConfigBuff, sizeof ConfigBuff, F) != NULL) {
  31.         if ((p = strchr(ConfigBuff, '\n')) != NULL)
  32.         *p = '\0';
  33.         if (ConfigBuff[0] == '\0' || ConfigBuff[0] == COMMENT_CHAR)
  34.         continue;
  35.         if (ConfigBuff[0] == c
  36.          && ConfigBuff[i] == ':'
  37.          && EQn(ConfigBuff, value, i)) {
  38.         (void)fclose(F);
  39.         for (p = &ConfigBuff[i + 1]; ISWHITE(*p); p++)
  40.             continue;
  41.         return p;
  42.         }
  43.     }
  44.     (void)fclose(F);
  45.     }
  46.     return NULL;
  47. }
  48.  
  49.  
  50. /*
  51. **  Get a configuration parameter, usually from reading the file.
  52. */
  53. char *
  54. GetConfigValue(value)
  55.     register char    *value;
  56. {
  57.     register char    *p;
  58.  
  59.     /* Some environment variables override the file. */
  60.     if (EQ(value, _CONF_SERVER)
  61.      && (p = getenv(_ENV_NNTPSERVER)) != NULL)
  62.     return p;
  63.     if (EQ(value, _CONF_ORGANIZATION)
  64.      && (p = getenv(_ENV_ORGANIZATION)) != NULL)
  65.     return p;
  66.     if (EQ(value, _CONF_FROMHOST)
  67.      && (p = getenv(_ENV_FROMHOST)) != NULL)
  68.     return p;
  69.  
  70.     if ((p = GetFileConfigValue(value)) != NULL)
  71.     return p;
  72.  
  73.     /* Some values have defaults if not in the file. */
  74.     if (EQ(value, _CONF_FROMHOST) || EQ(value, _CONF_PATHHOST))
  75.     return GetFQDN();
  76.     if (EQ(value, _CONF_CONTENTTYPE))
  77.     return "text/plain; charset=US-ASCII";
  78.     if (EQ(value, _CONF_ENCODING))
  79.     return "7bit";
  80.     return NULL;
  81. }
  82.